
#delimit;
clear all;
version 13.1;
pause on;
program drop _all;
capture log close;
set more off;

/*INSERT FOLDER PATH*/
cd /;

use related_pubs_descriptives.dta, clear;


foreach defn in strct {;

byhist stk_cites_it if stk_cites_it<100 & subv_of_trth_`defn'==1, bin(100) by(rltd) frac tw(xscale(log) ytitle("Fraction of Articles") xlabel(1 2 5 10 25 50 100, labsize(small)) ylabel(0(.05).25, labsize(small) angle(horizontal) format(%15.2f)) legend(label(1 "NN Controls") label(2 "Relateds") position(1) ring(0) cols(1) size(small)) saving(graphs/baseline_stk_cites_`defn'.gph, replace));

tab rltd if subv_of_trth_`defn'==1;
tab rltd if pubyear>srce_year & subv_of_trth_`defn'==1;
tab rltd if pubyear<srce_year & subv_of_trth_`defn'==1;

estimates drop _all;
quietly estpost tabstat pubyear nbauthors score ranking age_at_rtrct pblshd_after_rtrct stk_cites_it stk_cites_corp_it cited_by_patent if subv_of_trth_`defn'==1, by(rltd) stat(count mean p50 sd min max) c(s) nototal;
esttab, cells("count(label(Nb. Articles) fmt(%15.0fc)) mean(label(Mean) fmt(%15.3f)) p50(label(Median) fmt(%15.0f)) sd(label(Std. Dev.) fmt(%15.3f)) min(label(Min.) fmt(%15.0f)) max(label(Max.) fmt(%15.0f))") noobs nomtitle nonumber label;
esttab using tables/desc_stats_pmid_`defn'.rtf, cells("count(label(Nb. Articles) fmt(%15.0fc)) mean(label(Mean) fmt(%15.3f)) p50(label(Median) fmt(%15.0f)) 
sd(label(Std. Dev.) fmt(%15.3f)) min(label(Min.) fmt(%15.0f)) max(label(Max.) fmt(%15.0f))") noobs nomtitle nonumber label replace;
quietly estpost tabstat cites_rtrctd_piece if pubyear>srce_year & subv_of_trth_`defn'==1, by(rltd) stat(mean p50 sd min max count) c(s) nototal;
esttab, cells("count(label(Nb. Articles) fmt(%15.0fc)) mean(label(Mean) fmt(%15.3f)) p50(label(Median) fmt(%15.0f)) sd(label(Std. Dev.) fmt(%15.3f)) min(label(Min.) fmt(%15.0f)) max(label(Max.) fmt(%15.0f))") noobs nomtitle nonumber label replace;
esttab using tables/desc_stats_pmid_`defn'.rtf, cells("count(label(Nb. Articles) fmt(%15.0fc)) mean(label(Mean) fmt(%15.3f)) p50(label(Median) fmt(%15.0f)) sd(label(Std. Dev.) fmt(%15.3f)) min(label(Min.) fmt(%15.0f)) max(label(Max.) fmt(%15.0f))") noobs nomtitle nonumber label append;
quietly estpost tabstat cited_by_rtrctd_piece if pubyear<srce_year & subv_of_trth_`defn'==1, by(rltd) stat(mean p50 sd min max count) c(s) nototal;
esttab, cells("count(label(Nb. Articles) fmt(%15.0fc)) mean(label(Mean) fmt(%15.3f)) p50(label(Median) fmt(%15.0f)) sd(label(Std. Dev.) fmt(%15.3f)) min(label(Min.) fmt(%15.0f)) max(label(Max.) fmt(%15.0f))") noobs nomtitle nonumber label replace;
esttab using tables/desc_stats_pmid_`defn'.rtf, cells("count(label(Nb. Articles) fmt(%15.0fc)) mean(label(Mean) fmt(%15.3f)) p50(label(Median) fmt(%15.0f)) sd(label(Std. Dev.) fmt(%15.3f)) min(label(Min.) fmt(%15.0f)) max(label(Max.) fmt(%15.0f))") noobs nomtitle nonumber label append;

};
